function [best_is,opt_profits,EYI,EYin,ProfitPart]=prop_policy_v2(j_all,N)
addpath functions;
global P J I ci cI r LAMBDA CURRENT PIEs S
patient_number = size(j_all,2);
N=min(patient_number,N);%N不能超过给了病种的病人数。
ProfitPart=zeros(3,N);
EYI=zeros(1,N);
EYin=zeros(1,N);
S = zeros(I, J);
Line = j_all;
best_is = zeros(1, N);
opt_profits = zeros(1, N);

for n = 1:N
    CURRENT = n;
    j = Line(n);
    profits = zeros(1, I);
    for i = 1:I
        S_test = S;
        S_test(i, j) = S_test(i, j) + 1; % Replace rim & rimS
        Q = findQ_v2(S_test); % size(Q) = [I, CURRENT+1]
        R = findR_v1(Q);
        profits(i) = function_fQR_v1(Q,R,EYI,EYin,ProfitPart);
    end
    % return;
    i = find(profits == max(profits));
    best_is(n) = i(1);
    i = i(1);
    S(i, j) = S(i, j) + 1;
    Q = findQ_v2(S);
    R = findR_v1(Q);
    [opt_profits(n),EYI,EYin,ProfitPart] = function_fQR_v1(Q,R,EYI,EYin,ProfitPart);
end
return